#include "stdafx.h"
#include "ckGDBDataSource.h"
#include "ckEnumDataset.h"

namespace ck
{

	GDBDataSource::GDBDataSource()
	{
		m_type = ckFolderDataSource;
		m_pWorkspace = NULL;
	}
	
	GDBDataSource::~GDBDataSource()
	{
	}

	RESULTCODE GDBDataSource::Open()
	{
		IWorkspaceFactoryPtr pWorksFactory;
		HRESULT hr = pWorksFactory.CreateInstance(CLSID_FileGDBWorkspaceFactory);
		if (FAILED(hr))
		{
			return RC_FAILURE;
		}

		hr = pWorksFactory->OpenFromFile(CComBSTR(m_strPath.c_str()), 0, &m_pWorkspace);
		if (FAILED(hr))
		{
			return RC_FAILURE;
		}

		IDatasetPtr pDataset;
		IEnumDatasetPtr pEnumDataset;
		hr = m_pWorkspace->get_Datasets(esriDTAny, &pEnumDataset);

		pEnumDataset->Reset();
		while (SUCCEEDED(pEnumDataset->Next(&pDataset)))
		{
			if (pDataset == NULL)
			{
				break;;
			}
			CComBSTR bstrName;
			pDataset->get_Name(&bstrName);
			esriDatasetType type;
			pDataset->get_Type(&type);

			_bstr_t b = bstrName;
			char* szName = b;

			TRACE1("%s\n", szName);

		}

		return RC_SUCCESS;
	}

	RESULTCODE GDBDataSource::Close()
	{
		return RC_SUCCESS;
	}

	RESULTCODE GDBDataSource::Find(DatasetProcessor* pProcessor, DatasetFilter* pFilter)
	{
		return RC_SUCCESS;
	}

	data::EnumDataset* GDBDataSource::GetDatasets(ckDataProductType type)
	{
		data::EnumDataset* pDatasets = new data::EnumDataset();

		return pDatasets;
	}
}
